package com.xyyl.patient.service.article;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xyyl.patient.core.constant.AppEnum;
import com.xyyl.patient.core.support.Pager;
import com.xyyl.patient.entity.article.ArticleEntity;
import com.xyyl.patient.mapper.article.ArticleMapper;

@Service("articleService")
public class ArticleServiceImp implements ArticleService {

	@Autowired
	private ArticleMapper articleMapper;

	@Override
	public List<ArticleEntity> queryList(Pager pager) {

		return articleMapper.queryForPage(pager);
	}

	@Override
	public ArticleEntity getArticleById(Integer articleId) {
		ArticleEntity articleEntity = articleMapper.findArticleDetail(articleId);
		if (articleEntity != null) {
			articleEntity = addReadCount(articleEntity);
		}
		return articleEntity;
	}

	@Override
	public List<ArticleEntity> findArticleIndex(Pager pager) {
		List<ArticleEntity> articleList = articleMapper.findArticleIndex(pager);
		return articleList;
	}

	/**
	 * 
	 * @Title: addReadCount
	 * @Description: 阅读文章数累积增加
	 * @param @param articleEntity
	 * @param @return    参数
	 * @return ArticleEntity    返回类型
	 * @throws
	 */
	private ArticleEntity addReadCount(ArticleEntity articleEntity) {
		int readcount = articleEntity.getReadcount();
		articleEntity.setReadcount(readcount + AppEnum.common.article_type_readcount.getValue());
		articleMapper.update(articleEntity);
		return articleEntity;
	}

	@Override
	public List<ArticleEntity> queryArticleBannerList() {
		return articleMapper.queryArticleBannerList();
	}


}
